﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QLKH.View.Hotro;
using QLKH.View.Hoso;
using QLKH.View.Khachhang;
using QLKH.View.Sudung;
using QLKH.View.Baocao;
using QLKH.View.VungKhuvuc;
using QLKH.View.Dialy;
using QLKH.View.Khuyenmai;
using QLKH.View.Nhanvien;
using QLKH.View.Vattu;
using QLKH.View.report;
using QLKH.PopUp.taodulieu;
using QLKH.View.Hoadon;
using QLKH.View.reportNhieuThang;
using QLKH.View.congno;

namespace QLKH
{
    public partial class main : Form
    {
        public main()
        {
            InitializeComponent();
            ConfigForm.width = Screen.PrimaryScreen.WorkingArea.Width;
            ConfigForm.height = Screen.PrimaryScreen.WorkingArea.Height;
            ConfigForm.hmain = ConfigForm.height - panelheader.Height - mainmenu.Height - panelfooter.Height;
            ConfigForm.wmain = ConfigForm.width;

            this.Width = ConfigForm.width;

            this.Height = ConfigForm.height;

            labeluserName.Text = DataUser.UserName;
        }

        private void main_Load(object sender, EventArgs e)
        {
            panmain.Controls.Clear();
            gioithieu usfritem = new gioithieu();
            usfritem.Location = new Point(0, 0);
            usfritem.Dock = DockStyle.Fill;
            panmain.Controls.Add(usfritem);
            //Phan quyen
            string quyen = DataUser.RoleName;
            if (quyen != "all")
            {
                // Ho So
                if (quyen.LastIndexOf("1") > 0 || quyen.LastIndexOf("2") > 0)
                    root_hoso.Visible = true;
                else
                    root_hoso.Visible = false;

                if (quyen.LastIndexOf("1") > 0)
                    child_dangki.Visible = true;
                else
                    child_dangki.Visible = false;

                if (quyen.LastIndexOf("2") > 0)
                    child_hopdong.Visible = true;
                else
                    child_hopdong.Visible = false;
                // Khach hang
                if (quyen.LastIndexOf("3") > 0)
                    root_khachhang.Visible = true;
                else
                    root_khachhang.Visible = false;
                //Thong tin su dung
                if (quyen.LastIndexOf("4") > 0 || quyen.LastIndexOf("5") > 0)
                    root_sudung.Visible = true;
                else
                    root_sudung.Visible = false;

                if (quyen.LastIndexOf("4") > 0)
                {
                    child_sudungtang.Visible = false;
                    child_lichsutieuthu.Visible = false;
                    child_nhapsudung.Visible = false;
                }
                else
                {
                    child_sudungtang.Visible = false;
                    child_lichsutieuthu.Visible = false;
                    child_nhapsudung.Visible = false;
                }

                if (quyen.LastIndexOf("5") > 0)
                    child_tinhcuoc.Visible = false;
                else
                    child_tinhcuoc.Visible = false;
                // bao cao - in hoa don
                if (quyen.LastIndexOf("6") > 0 || quyen.LastIndexOf("7") > 0)
                {
                    root_baocao.Visible = true;
                    root_BCnhieuthang.Visible = true;
                }
                else
                {
                    root_baocao.Visible = false;
                    root_BCnhieuthang.Visible = false;
                }

                if (quyen.LastIndexOf("6") > 0)
                {
                    child_sudung0.Visible = true;
                    child_sudungnho4.Visible = true;
                    child_sudunggiam.Visible = true;
                    child_sudungtang.Visible = true;
                    child_dongho5.Visible = true;
                    child_coquancoPNT.Visible = true;
                    child_coquankoPNT.Visible = true;
                    child_tiennuoctunhan.Visible = true;
                    child_tunhanghitay.Visible = true;
                    chirld_thaydh.Visible = true;
                    Chirld_dskhmoi.Visible = true;
                    chirld_dsnghingo.Visible = true;
                }
                else
                {
                    child_sudung0.Visible = false;
                    child_sudungnho4.Visible = false;
                    child_sudunggiam.Visible = false;
                    child_sudungtang.Visible = false;
                    child_dongho5.Visible = false;
                    child_coquancoPNT.Visible = false;
                    child_coquankoPNT.Visible = false;
                    child_tiennuoctunhan.Visible = false;
                    child_tunhanghitay.Visible = false;
                    chirld_thaydh.Visible = false;
                    Chirld_dskhmoi.Visible = false;
                    chirld_dsnghingo.Visible = false;
                }

                if (quyen.LastIndexOf("7") > 0)
                    child_inhoadon.Visible = true;
                else
                    child_inhoadon.Visible = false;
                //cong no
                if (quyen.LastIndexOf("8") > 0)
                    root_congno.Visible = true;
                else
                    root_congno.Visible = false;
                //vung khu vuc - dia ly
                if (quyen.LastIndexOf("9") > 0)
                {
                    root_dialy.Visible = true;
                    root_vungkhuvuc.Visible = true;
                }
                else
                {
                    root_dialy.Visible = false;
                    root_vungkhuvuc.Visible = false;
                }
                //khuyen mai
                if (quyen.LastIndexOf("10") > 0)
                    root_giakhuyenmai.Visible = true;
                else
                    root_giakhuyenmai.Visible = false;
                // nhan vien
                if (quyen.LastIndexOf("11") > 0)
                    root_nhanvien.Visible = true;
                else
                    root_nhanvien.Visible = false;
                //dong ho
                if (quyen.LastIndexOf("12") > 0)
                    root_dongho.Visible = true;
                else
                    root_dongho.Visible = false;
            }
        }

        private void btminsize_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
        }

        private void btquit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void child_dangki_Click(object sender, EventArgs e)
        {
            panmain.Controls.Clear();
            dsDangki usfritem = new dsDangki();
            usfritem.Location = new Point(0, 0);
            usfritem.Dock = DockStyle.Fill;
            panmain.Controls.Add(usfritem);
        }

        private void child_hopdong_Click(object sender, EventArgs e)
        {
            panmain.Controls.Clear();
            sdHopdong usfritem = new sdHopdong();
            usfritem.Location = new Point(0, 0);
            usfritem.Dock = DockStyle.Fill;
            panmain.Controls.Add(usfritem);
        }

        private void child_dskhachhang_Click(object sender, EventArgs e)
        {
            panmain.Controls.Clear();
            dsKhachhang usfritem = new dsKhachhang();
            usfritem.Location = new Point(0, 0);
            usfritem.Dock = DockStyle.Fill;
            panmain.Controls.Add(usfritem);
        }

        private void child_timkiemkh_Click(object sender, EventArgs e)
        {
            panmain.Controls.Clear();
            Timkiem usfritem = new Timkiem();
            usfritem.Location = new Point(0, 0);
            usfritem.Dock = DockStyle.Fill;
            panmain.Controls.Add(usfritem);
        }

        private void child_thongtinxuly_Click(object sender, EventArgs e)
        {
            panmain.Controls.Clear();
            TTXuly usfritem = new TTXuly();
            usfritem.Location = new Point(0, 0);
            usfritem.Dock = DockStyle.Fill;
            panmain.Controls.Add(usfritem);
        }
        // Thong tin su dung
        private void child_sudungthang_Click(object sender, EventArgs e)
        {
            //panmain.Controls.Clear();
            //dsSudungthang usfritem = new dsSudungthang();
            //usfritem.Location = new Point(0, 0);
            //usfritem.Dock = DockStyle.Fill;
            //panmain.Controls.Add(usfritem);
        }

        private void child_lichsutieuthu_Click(object sender, EventArgs e)
        {
            panmain.Controls.Clear();
            Lichsutieuthu usfritem = new Lichsutieuthu();
            usfritem.Location = new Point(0, 0);
            usfritem.Dock = DockStyle.Fill;
            panmain.Controls.Add(usfritem);
        }

        private void child_nhapsudung_Click(object sender, EventArgs e)
        {
            panmain.Controls.Clear();
            Nhapso usfritem = new Nhapso();
            usfritem.Location = new Point(0, 0);
            usfritem.Dock = DockStyle.Fill;
            panmain.Controls.Add(usfritem);
        }

        private void child_sudung0_Click(object sender, EventArgs e)
        {
            ReportSuDung0m3 sdk = new ReportSuDung0m3();
            sdk.ShowDialog();
            //panmain.Controls.Clear();
            //dsSudung0 usfritem = new dsSudung0();
            //usfritem.Location = new Point(0, 0);
            //usfritem.Dock = DockStyle.Fill;
            //panmain.Controls.Add(usfritem);
        }

        private void child_sudungnho4_Click(object sender, EventArgs e)
        {
            ReportSuDung1den3 sdt = new ReportSuDung1den3();
            sdt.ShowDialog();
            //panmain.Controls.Clear();
            //dsSudungnho4 usfritem = new dsSudungnho4();
            //usfritem.Location = new Point(0, 0);
            //usfritem.Dock = DockStyle.Fill;
            //panmain.Controls.Add(usfritem);
        }

        private void child_sudunggiam_Click(object sender, EventArgs e)
        {
            //panmain.Controls.Clear();
            //dsSudunggiam usfritem = new dsSudunggiam();
            //usfritem.Location = new Point(0, 0);
            //usfritem.Dock = DockStyle.Fill;
            //panmain.Controls.Add(usfritem);
            ReportSuDungGiam sdg = new ReportSuDungGiam();
            sdg.ShowDialog();
        }

        private void child_sudungtang_Click(object sender, EventArgs e)
        {
            ReportSuDungTang sdt = new ReportSuDungTang();
            sdt.ShowDialog();
            //panmain.Controls.Clear();
            //dsSudungtang usfritem = new dsSudungtang();
            //usfritem.Location = new Point(0, 0);
            //usfritem.Dock = DockStyle.Fill;
            //panmain.Controls.Add(usfritem);
        }

        private void child_dongho5_Click(object sender, EventArgs e)
        {
            ReportDHTren5Nam dh5nam = new ReportDHTren5Nam();
            dh5nam.ShowDialog();
            //panmain.Controls.Clear();
            //dsDHquahan usfritem = new dsDHquahan();
            //usfritem.Location = new Point(0, 0);
            //usfritem.Dock = DockStyle.Fill;
            //panmain.Controls.Add(usfritem);
        }

        private void child_inhoadon_Click(object sender, EventArgs e)
        {
            InHoaDon itfr = new InHoaDon();
            itfr.ShowDialog();
        }

        private void child_tinhcuoc_Click(object sender, EventArgs e)
        {
            Tinhcuoc itfr = new Tinhcuoc();
            itfr.ShowDialog();
        }
        //Công nợ
        private void child_congno_Click(object sender, EventArgs e)
        {
            panmain.Controls.Clear();
            dscongno usfritem = new dscongno();
            usfritem.Location = new Point(0, 0);
            usfritem.Dock = DockStyle.Fill;
            panmain.Controls.Add(usfritem);
            //MessageBox.Show("Chức năng đang được hoàn thiện");
        }
        //Quản lý ADMINSTRATOR
        //Vùng tiêu thụ
        private void child_dsvung_Click(object sender, EventArgs e)
        {
            panmain.Controls.Clear();
            dsVung usfritem = new dsVung();
            usfritem.Location = new Point(0, 0);
            usfritem.Dock = DockStyle.Fill;
            panmain.Controls.Add(usfritem);
        }
        //Khu vực tiêu thụ
        private void child_dskhuvuc_Click(object sender, EventArgs e)
        {
            panmain.Controls.Clear();
            dsKhuvuc usfritem = new dsKhuvuc();
            usfritem.Location = new Point(0, 0);
            usfritem.Dock = DockStyle.Fill;
            panmain.Controls.Add(usfritem);
        }
        //Đồng hồ tổng
        private void child_dsdhtong_Click(object sender, EventArgs e)
        {
            panmain.Controls.Clear();
            dsDHTong usfritem = new dsDHTong();
            usfritem.Location = new Point(0, 0);
            usfritem.Dock = DockStyle.Fill;
            panmain.Controls.Add(usfritem);
        }
        //Tỉnh/TP
        private void child_dstinhtp_Click(object sender, EventArgs e)
        {
            panmain.Controls.Clear();
            dsTinhTP usfritem = new dsTinhTP();
            usfritem.Location = new Point(0, 0);
            usfritem.Dock = DockStyle.Fill;
            panmain.Controls.Add(usfritem);
        }
        //Quận/Huyện
        private void child_dsquanhuyen_Click(object sender, EventArgs e)
        {
            panmain.Controls.Clear();
            dsQuanHuyen usfritem = new dsQuanHuyen();
            usfritem.Location = new Point(0, 0);
            usfritem.Dock = DockStyle.Fill;
            panmain.Controls.Add(usfritem);
        }
        //Phường/Xã
        private void child_dsphuongxa_Click(object sender, EventArgs e)
        {
            panmain.Controls.Clear();
            dsPhuongXa usfritem = new dsPhuongXa();
            usfritem.Location = new Point(0, 0);
            usfritem.Dock = DockStyle.Fill;
            panmain.Controls.Add(usfritem);
        }
        //Tổ dân
        private void child_dstodan_Click(object sender, EventArgs e)
        {
            panmain.Controls.Clear();
            dsTodan usfritem = new dsTodan();
            usfritem.Location = new Point(0, 0);
            usfritem.Dock = DockStyle.Fill;
            panmain.Controls.Add(usfritem);
        }
        //Đường
        private void child_dsduong_Click(object sender, EventArgs e)
        {
            panmain.Controls.Clear();
            dsDuong usfritem = new dsDuong();
            usfritem.Location = new Point(0, 0);
            usfritem.Dock = DockStyle.Fill;
            panmain.Controls.Add(usfritem);
        }
        //Phố
        private void child_dspho_Click(object sender, EventArgs e)
        {
            panmain.Controls.Clear();
            dsPho usfritem = new dsPho();
            usfritem.Location = new Point(0, 0);
            usfritem.Dock = DockStyle.Fill;
            panmain.Controls.Add(usfritem);
        }
        //Giá
        private void child_dsgia_Click(object sender, EventArgs e)
        {
            panmain.Controls.Clear();
            dsGia usfritem = new dsGia();
            usfritem.Location = new Point(0, 0);
            usfritem.Dock = DockStyle.Fill;
            panmain.Controls.Add(usfritem);
        }
        //Khuyến mãi
        private void child_dskhuyenmai_Click(object sender, EventArgs e)
        {
            panmain.Controls.Clear();
            dsKhuyenmai usfritem = new dsKhuyenmai();
            usfritem.Location = new Point(0, 0);
            usfritem.Dock = DockStyle.Fill;
            panmain.Controls.Add(usfritem);
        }
        //Nhân viện
        private void child_nhanvien_Click(object sender, EventArgs e)
        {
            panmain.Controls.Clear();
            dsNhanvien usfritem = new dsNhanvien();
            usfritem.Location = new Point(0, 0);
            usfritem.Dock = DockStyle.Fill;
            panmain.Controls.Add(usfritem);
        }
        //Danh sách đồng hồ
        private void child_dsdongho_Click(object sender, EventArgs e)
        {
            panmain.Controls.Clear();
            dsDongho usfritem = new dsDongho();
            usfritem.Location = new Point(0, 0);
            usfritem.Dock = DockStyle.Fill;
            panmain.Controls.Add(usfritem);
        }

        private void child_coquancoPNT_Click(object sender, EventArgs e)
        {
            reportCQcophi itfr = new reportCQcophi();
            itfr.ShowDialog();
        }

        private void child_coquankoPNT_Click(object sender, EventArgs e)
        {
            reportCQKoPhi cqko = new reportCQKoPhi();
            cqko.ShowDialog();
        }

        private void child_tiennuoctunhan_Click(object sender, EventArgs e)
        {
            reportTuGiaDung tgd = new reportTuGiaDung();
            tgd.ShowDialog();
        }

        private void child_tunhanghitay_Click(object sender, EventArgs e)
        {
            reportTuGiaNVGhi tgnvg = new reportTuGiaNVGhi();
            tgnvg.ShowDialog();
        }

        private void Chidl_taobangsd_Click(object sender, EventArgs e)
        {
            Taobangsudung tbsd = new Taobangsudung();
            tbsd.ShowDialog();
        }

        private void chidl_sdThang_Click(object sender, EventArgs e)
        {
            panmain.Controls.Clear();
            UpdateData usfritem = new UpdateData();
            usfritem.Location = new Point(0, 0);
            usfritem.Dock = DockStyle.Fill;
            panmain.Controls.Add(usfritem);
        }

        private void chirld_thaydh_Click(object sender, EventArgs e)
        {
            reportDSKhachHangThayDH tdhth = new reportDSKhachHangThayDH();
            tdhth.ShowDialog();
        }

        private void chidl_loaidh_Click(object sender, EventArgs e)
        {
            panmain.Controls.Clear();
            dsLoaiDongHo usfritem = new dsLoaiDongHo();
            usfritem.Location = new Point(0, 0);
            usfritem.Dock = DockStyle.Fill;
            panmain.Controls.Add(usfritem);
        }

        private void Chirld_tuyen_Click(object sender, EventArgs e)
        {
            panmain.Controls.Clear();
            dsTuyen usfritem = new dsTuyen();
            usfritem.Location = new Point(0, 0);
            usfritem.Dock = DockStyle.Fill;
            panmain.Controls.Add(usfritem);
        }

        private void Chirld_dskhmoi_Click(object sender, EventArgs e)
        {
            ReportKhachHangLapMoi rpkhm = new ReportKhachHangLapMoi();
            rpkhm.ShowDialog();
        }

        private void chirld_dsnghingo_Click(object sender, EventArgs e)
        {
            ReportKhachHangNghiNgo rpng = new ReportKhachHangNghiNgo();
            rpng.ShowDialog();
        }

        private void chirld_inHDCaNhan_Click(object sender, EventArgs e)
        {
            ViewHoaDonCaNhan hdcn = new ViewHoaDonCaNhan();
            hdcn.ShowDialog();
        }

        private void chirld_0m3_Click(object sender, EventArgs e)
        {
            BaoCaoKhachHang0m3NhieuThang bcnt = new BaoCaoKhachHang0m3NhieuThang();
            bcnt.ShowDialog();
        }

        private void chirld_1den3m3_Click(object sender, EventArgs e)
        {
            BaoCaoKhachHang1Den3m3 bcnt = new BaoCaoKhachHang1Den3m3();
            bcnt.ShowDialog();
        }

        private void Chirld_KhachHangMoi_Click(object sender, EventArgs e)
        {
            BaoCaoKhachHangMoiNhieuThang bcntkhm = new BaoCaoKhachHangMoiNhieuThang();
            bcntkhm.ShowDialog();
        }

        private void Chirld_DSKHThayDH_Click(object sender, EventArgs e)
        {
            BaoCaoNhieuThangKhachHangThayDH bcntkhthaydh = new BaoCaoNhieuThangKhachHangThayDH();
            bcntkhthaydh.ShowDialog();
        }

        private void chirld_lichsudh_Click(object sender, EventArgs e)
        {
            ReportlichSuDHKH rplsdh = new ReportlichSuDHKH();
            rplsdh.ShowDialog();
        }

        private void chirld_TuGiaDungNuoc_Click(object sender, EventArgs e)
        {
            BaoCaoNhieuThangKHSuDungNuoc bcntdn = new BaoCaoNhieuThangKHSuDungNuoc();
            bcntdn.ShowDialog();
        }

        private void Chirld_CQDungNuocCoPhi_Click(object sender, EventArgs e)
        {
            BaoCaoNhieuThangCQCoPhiDungNuoc cqcpnt = new BaoCaoNhieuThangCQCoPhiDungNuoc();
            cqcpnt.ShowDialog();
        }

        private void Chirld_CQKPhiNT_Click(object sender, EventArgs e)
        {
            BaoCaoNhieuThangCQKoPhi cqkpnt = new BaoCaoNhieuThangCQKoPhi();
            cqkpnt.ShowDialog();
        }

        private void chilren_qlcongno_Click(object sender, EventArgs e)
        {
            panmain.Controls.Clear();
            dsCongNoql usfritem = new dsCongNoql();
            usfritem.Location = new Point(0, 0);
            usfritem.Dock = DockStyle.Fill;
            panmain.Controls.Add(usfritem);
        }
    }
}
